package cc.abanlee.module.system.controller.admin.auth;


import cc.abanlee.framework.common.pojo.CommonResult;
import cc.abanlee.module.system.controller.admin.auth.vo.AuthLoginReqVO;
import cc.abanlee.module.system.controller.admin.auth.vo.AuthLoginRespVO;
import cc.abanlee.module.system.service.auth.AdminAuthService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

@RestController
@RequestMapping("/system/auth")
public class AuthController {

    @Resource
    private AdminAuthService authService;
    @PostMapping("/login")
    @PermitAll
    @ApiOperation("使用账号密码登录")
   // @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
        return CommonResult.success(authService.login(reqVO));
    }


    @PostMapping("/refresh-token")
    @PermitAll
    @ApiOperation("刷新令牌")
    @ApiImplicitParam(name = "refreshToken", value = "刷新令牌", required = true, dataTypeClass = String.class)
    //@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
    public CommonResult<AuthLoginRespVO> refreshToken(@RequestParam("refreshToken") String refreshToken) {
        return CommonResult.success(authService.refreshToken(refreshToken));
    }

}
